﻿#pragma once

#include <qwt_plot.h>
#include <stdlib.h>
#include <qpen.h>
#include <qwt_plot_layout.h>
#include <qwt_legend.h>
#include <qwt_legend_item.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_histogram.h>
#include <qwt_column_symbol.h>
#include <qwt_scale_div.h>
#include <qwt_series_data.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_marker.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_intervalcurve.h>
#include <qwt_legend.h>
#include <qwt_interval_symbol.h>
#include <qwt_symbol.h>
#include <qwt_series_data.h>
#include <qwt_text.h>
#include <qwt_scale_draw.h>
#include <qdatetime.h>

//#include "afxwin.h"
class Histogram;
class QwtPlotCurve;
class QwtPlotIntervalCurve;

class Plot : public QwtPlot
{
	Q_OBJECT

public:
	enum Mode{
		Bars,
		Tube
	};

	Plot(QWidget * = NULL);
	~Plot(){}
	void setupHistogram();
	void setupFunction();
	void clearFunktion();
	void clearHistogram();

	void populateHistogram(char* lawName, Qt::GlobalColor color);
	void populateFunction(int);
	QwtLegend *legend;
	QwtPlotItemList items;

	QwtPlotIntervalCurve *d_intervalCurve;
	QVector<QwtLegendItem *> legendItem;
	QVector<QwtPlotGrid *> grid;

	QwtPlotZoomer *zoomer;
	QVector<Histogram *> histogramCond; 
	QVector<QwtIntervalSample > _dataInterval;

public slots:
	void showItem(QwtPlotItem *, bool on);

private:
	void insertData(QVector<QwtIntervalSample> &,const QColor &color);
};

class Histogram : public QwtPlotHistogram
{
public:
	Histogram(const QString &, const QColor &);

	void setColorHist(const QColor &, int alpha = 180);
	void setValues(uint numValues, double *);
};

class Grid: public QwtPlotGrid
{
public:
	Grid()
	{
		enableXMin(true);
		setMajPen(QPen(Qt::white, 0, Qt::DotLine));
		setMinPen(QPen(Qt::gray, 0, Qt::DotLine));
	}

	virtual void updateScaleDiv(const QwtScaleDiv &xMap,
		const QwtScaleDiv &yMap)
	{
		QList<double> ticks[QwtScaleDiv::NTickTypes];

		ticks[QwtScaleDiv::MajorTick] = xMap.ticks(QwtScaleDiv::MediumTick);
		ticks[QwtScaleDiv::MinorTick] = xMap.ticks(QwtScaleDiv::MinorTick);

		QwtPlotGrid::updateScaleDiv(
			QwtScaleDiv(xMap.lowerBound(), xMap.upperBound(), ticks),
			yMap );
	}
};
